<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="申请人" prop="applyBy">
        <el-input
          v-model="queryParams.applyBy"
          placeholder="请输入申请人"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经办人" prop="handlerName">
        <el-input
          v-model="queryParams.handlerName"
          placeholder="请输入经办人"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>

      <el-button
        class="appaybtn"
        @click="onapply"
        type="primary"
        style="float: right;"
        size="mini"
        v-if="isMy"
        >申请用印</el-button
      >
      <el-button
        v-else
        class="appaybtn"
        @click="onapply"
        type="primary"
        style="float: right;"
        size="mini"
        v-hasPermi="['sealmanage:appay']"
        >申请用印</el-button
      >
    </el-form>

    <el-table v-loading="loading" :data="roleList" :height="tableHeight">
      <el-table-column label="申请人" prop="applyBy"  width="100"/>

      <el-table-column
        label="经办人"
        prop="handlerName"
        width="100"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="用印文件说明" show-overflow-tooltip min-width="220"  prop="description" />
      <el-table-column label="加盖何种公章" width="100" prop="stampType">
        <template slot-scope="scope">
          <dict-tag
              :options="dict.type.seal_manage"
              :value="scope.row.stampType"
            />
        </template>
      </el-table-column>
      <el-table-column label="服务费支付情况" show-overflow-tooltip min-width="150" prop="servicePayment" />
      <el-table-column label="文件份数" width="100" prop="fileCount" />
      <el-table-column label="文件类别" width="100" prop="fileCategory">
        <template slot-scope="scope">
          <dict-tag
              :options="dict.type.seal_file_type"
              :value="scope.row.fileCategory"
            />
        </template>
      </el-table-column>

      <el-table-column
        label="审批状态"
        prop="auditStatus"
        width="100"
      >
        <template slot-scope="scope">
          <dict-tag
              :options="dict.type.approval_status"
              :value="scope.row.auditStatus"
            />
        </template>
      </el-table-column>
      <el-table-column
        label="审批原因"
        prop="remark"
        show-overflow-tooltip
        width="130"
      />
      <el-table-column
        label="操作"
        align="center"
        width="100"
        fixed="right"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope" v-show="isMy">
          <el-button
            v-if="scope.row.auditStatus != 0"
            size="mini"
            type="text"
            @click="onEidt(scope.row, 2)"
            >查看</el-button
          >
          <el-button
            :disabled="
              userId != scope.row.applyById
            "
            size="mini"
            v-else
            type="text"
            @click="onEidt(scope.row, 1)"
            >编辑</el-button
          >

        </template>
        <template slot-scope="scope"v-show="!isMy">

          <el-button
            v-if="scope.row.auditStatus != 0"
            size="mini"
            type="text"
            @click="onEidt(scope.row, 2)"
            v-hasPermi="['sealmanage:edit']"
            >查看</el-button
          >
          <el-button
            :disabled="
              userId != scope.row.applyById
            "
            size="mini"
            v-else
            type="text"
            @click="onEidt(scope.row, 1)"
            v-hasPermi="['sealmanage:edit']"
            >编辑</el-button
          >

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <sealmodalVue ref="sealmodalVue" @submit="handleQuery" />
  </div>
</template>

<script>
import { applicationlist } from "@/api/met";
import sealmodalVue from "./sealmodal.vue";
import { mapState } from "vuex";
export default {
  name: "manage",
  components: { sealmodalVue },
  dicts: ["sys_normal_disable", "approval_status", "seal_file_type", "seal_manage"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      total: 0,
      // 角色表格数据
      roleList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        handlerName: "",
        applyBy: undefined,
        caseName: undefined,
        orderByColumn:'updateTime',
        isAsc: 'desc',
        auditor: this.isMy ? '1' : '0'
      },
    };
  },
  props: {
    isMy: Boolean
  },
  created() {
    this.getList();
  },
  mounted() {
    console.log(this.$route.query, "======");
    if (this.$route.query.row) {
      let data = JSON.parse(this.$route.query.row);
      this.onEidt(data,2);
    }
  },
  computed: {
    ...mapState({
      userName: (state) => state.user.name,
      userId: (state) => state.user.id,
    }),
    tableHeight() {
      return this.$store.state?.app?.clientHeight;
    },
  },
  methods: {

    /** 查询角色列表 */
    getList() {
      this.loading = true;
      applicationlist(this.addDateRange(this.queryParams)).then((response) => {
        this.roleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //归还
    async onback(row, type) {
      console.log(row);
      let that = this;
      this.$modal
        .confirm(`是否确认归还所属案件为${row.caseName}`)
        .then(()=> {
          console.log("归还接口");
          that.getList();
          that.$modal.msgSuccess("操作成功");
        });
    },
    onEidt(row, type) {
      this.$refs.sealmodalVue.open(row, type);
    },
    //用印申请
    onapply() {
      this.$refs.sealmodalVue.open();
    },
  },
};
</script>
<style scoped lang="scss">
.appaybtn {
  float: right;
}
</styl>
